﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace GameObjects
{
    public class StupidMonsterMove : IMoveBehavior
    {
        private Character _character;
        public Character Character
        {
            get { return _character; }
            set { _character = value; }
        }
        List<Character> targets;

        public StupidMonsterMove(Character character)
        {
            this._character = character;
            this.targets = new List<Character>();
        }

        public StupidMonsterMove(Character character, params Character[] targets)
        {
            this._character = character;
            this.targets = new List<Character>(targets);
        }

        public void Move()
        {
            if (targets.Count != 0)
            {
                // ищем ближайшего врага
                // находим расстояние до ближайшего врага
                Vector2 delta = (targets[0].Position - _character.Position);
                for (int i = 0; i < targets.Count; i++)
                {
                    Vector2 tmpDelta = (targets[i].Position - _character.Position);
                    if (tmpDelta.Length() < delta.Length())
                        delta = tmpDelta;
                }
                _character.Position.X += delta.X > 0 ? 1 : (delta.X < 0 ? -1 : 0);
                _character.Position.Y += delta.Y > 0 ? 1 : (delta.Y < 0 ? -1 : 0);
            }
        }
    }
}
